﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Onuprova.Anaglyphing.ImageProcessor;

namespace _3D_Processor.Controls
{
    public partial class AdjustmentButtons : UserControl
    {

        public AdjustmentButtons()
        {
            InitializeComponent();
        }

        private TransformFactor transformfactor;

        /// <summary>
        /// Adjustment parameter for the image
        /// </summary>
        public AdjustmentParameter Adjustment
        {
            get
            {
                AdjustmentParameter ap = new AdjustmentParameter();
                ap.ColourFilter = new ColourFilterConfiguration(((float)RedBar.Value) / 255, ((float)GreenBar.Value) / 255, ((float)BlueBar.Value) / 255);
                ap.Transformation = transformfactor;
                return ap;
            }
            set
            {
                transformfactor = value.Transformation;
                RedBar.Value = (int)(value.ColourFilter.Red * 255);
                RedValue.Text = Math.Round((((decimal)RedBar.Value) / 255) * 100, 2) + "%";
                GreenBar.Value = (int)(value.ColourFilter.Green * 255);
                GreenValue.Text = Math.Round((((decimal)GreenBar.Value) / 255) * 100, 2) + "%";
                BlueBar.Value = (int)(value.ColourFilter.Blue * 255);
                BlueValue.Text = Math.Round((((decimal)BlueBar.Value) / 255) * 100, 2) + "%";
                ChannelColour.BackColor = Color.FromArgb((int)(value.ColourFilter.Red * 255), (int)(value.ColourFilter.Green * 255), (int)(value.ColourFilter.Blue * 255));
            }
        }

        /// <summary>
        /// AdjustMentChanged event to handle
        /// </summary>
        public event AdjustmentParameterChangedEventHandler AdjustmentChanged;

        /// <summary>
        /// Scroll event handler for colour scrolls
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bar_Scroll(object sender, EventArgs e)
        {
            RedValue.Text = Math.Round((((decimal)RedBar.Value) / 255) * 100, 2) + "%";
            GreenValue.Text = Math.Round((((decimal)GreenBar.Value) / 255) * 100, 2) + "%";
            BlueValue.Text = Math.Round((((decimal)BlueBar.Value) / 255) * 100, 2) + "%";
            ChannelColour.BackColor = Color.FromArgb((int)(Adjustment.ColourFilter.Red * 255), (int)(Adjustment.ColourFilter.Green * 255), (int)(Adjustment.ColourFilter.Blue * 255));
            if (AdjustmentChanged != null) AdjustmentChanged(Adjustment);
        }

        /// <summary>
        /// Click event handler for buttons
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Buttom_Click(object sender, EventArgs e)
        {
            PictureBox button = (PictureBox)sender;
            switch (button.Name)
            {
                case "UpButton":
                    transformfactor.TopShift--;
                    break;
                case "DownButton":
                    transformfactor.TopShift++;
                    break;
                case "LeftButton":
                    transformfactor.LeftShift--;
                    break;
                case "RightButton":
                    transformfactor.LeftShift++;
                    break;
                case "ZoomInButtom":
                    transformfactor.ZoomFactor += 0.01f;
                    break;
                case "ZoomOutButton":
                    transformfactor.ZoomFactor -= 0.01f;
                    break;
                case "AntiClockwiseButton":
                    transformfactor.RotationAngle -= 0.1f;
                    break;
                case "ClockwiseButton":
                    transformfactor.RotationAngle += 0.1f;
                    break;
                default:
                    return;
            }
            if (AdjustmentChanged != null) AdjustmentChanged(Adjustment);
        }

    }
}
